<@override name="content">
<div class="row" style="margin-left:0px">
  <div class="span4 offset4" id="source-code">
    <span class="green">Problem<#if alpha?? && adminUser??>(<a href="problem/show/${solution.pid!}">${solution.pid!}</a>)</#if>
    </span>:
    <#if alpha??>
      <a href="contest/problem/${solution.cid!}-${alpha!}">${solution.cid!}-${alpha!} (${problemTitle!})</a>
    <#else>
      <a href="problem/show/${solution.pid!}">${solution.pid!} (${problemTitle!})</a>
    </#if>
    <span class="green">User</span>: <a
          href="user/profile/${(submitUser.name)!"Guest"}">${(submitUser.name)!"Guest"}</a> <br>
    <span class="green">Memory</span>: <span class="memory">${solution.memory!0}</span> KB
    <span class="green">Time</span>: <span class="time">${solution.time!0}</span> MS <br>
    <span class="green">Language</span>: ${language!}
    <span class="green">Result</span>: <span class="result" id="${resultName!}"
                                             sid="${solution.sid!}">${resultLongName!}</span>
    <#if (solution.test>0)> on test ${solution.test}</#if> <br>
  </div>
</div>

<div class="row" style="margin-left:0px">
  <div class="span12">
    <h2>Source Code</h2>
    <#if adminUser?? || user.uid==solution.uid>
      <span><a data-clipboard-target="source" id="copy" class="btn btn-primary">
        <i class="fa fa-files-o" aria-hidden="true"></i> Copy to Clipboard</a></span>
      <span id="message"></span>
    </#if>
    <#if !alpha??>
      <span class="pull-right">
    <#if adminUser??><a class="btn btn-danger" href="solution/rejudge/${solution.sid!}">Rejudge</a></#if>
        <#if adminUser?? || user.uid==solution.uid>
          <a class="btn btn-primary" href="problem/submit/${solution.pid!}?ajax=1&s=${solution.sid!}"
             data-toggle="modal"
             data-target="#submitModal"><i class="fa fa-code-fork" aria-hidden="true"></i> Fork</a>
        </#if>
    </span>
    </#if>
    <script id="source" class="hidden">${solution.source!}</script>
    <textarea class="brush: ${brush!'cpp'} auto-width" cols="120" rows="20">${solution.source!}</textarea>
  </div>
</div>

  <#if solution.error?has_content>
  <div class="row" style="margin-left:0px">
    <div class="span12">
      <h3><#if resultName=="CE">Compile Error<#else>Runtime Error</#if></h3>
      <pre class="error">${solution.error!}</pre>
    </div>
  </div>
  </#if>

  <#if resultName=="PE" || resultName=="WA" || resultName=="RE" || resultName=="RF" || resultName=="TLE" || resultName=="OLE" || resultName=="MLE" >
    <div class="row" style="margin-left:0px">
      <div class="span12">
        <h3>Input</h3>
        <pre class="info">${inputData!}</pre>
      </div>
    </div>
    <div class="row" style="margin-left:0px">
      <div class="span12">
        <h3>Output</h3>
        <pre class="info">${solution.wrong!}</pre>
      </div>
    </div>
  </#if>

  <#if adminUser?? && solution.systemError??>
  <div class="row" style="margin-left:0px">
    <div class="span12">
      <h3>System Error</h3>
      <pre class="error">${solution.systemError!}</pre>
    </div>
  </div>
  </#if>
  <#if !alpha?? && user??>
  <div class="modal hide fade problemModal" id="submitModal">
    <form class="" action="solution/save" method="post">
      <div class="modal-header">
        <button class="close" aria-hidden="true" data-dismiss="modal" type="button">×</button>
        <h3 id="submitModalLabel">
          Submit Problem ${solution.pid!}:<a href="problem/submit/${solution.pid!}?s=${solution.sid!}"
                                             title="Submit in another page" data-toggle="tooltip"
                                             data-placement="bottom">${problemTitle!}</a>
        </h3>
      </div>
      <div class="modal-body">
        <a href="problem/submit/${solution.pid!}" class="btn btn-primary">Submit</a>
      </div>
      <div class="modal-footer">
        <button type="submit" id="Submit" class="btn btn-primary">Submit</button>
        <button type="reset" class="btn btn-info">Reset</button>
        <button class="btn" data-dismiss="modal">Cancel</button>
      </div>
    </form>
  </div>
  </#if>
</@override>

<@override name="scripts">
<link type='text/css' rel='stylesheet' href='assets/syntaxhighlighter/styles/shCore.css'/>
<link type='text/css' rel='stylesheet' href='assets/syntaxhighlighter/styles/shThemeDefault.css'/>
<script src='assets/syntaxhighlighter/scripts/shCore.js' type='text/javascript'></script>

  <#if brush=='cpp'>
  <script src='assets/syntaxhighlighter/scripts/shBrushCpp.js' type='text/javascript'></script></#if>
  <#if brush=='java'>
  <script src='assets/syntaxhighlighter/scripts/shBrushJava.js' type='text/javascript'></script></#if>
  <#if brush=='pascal'>
  <script src='assets/syntaxhighlighter/scripts/shBrushDelphi.js' type='text/javascript'></script></#if>
  <#if brush=='python'>
  <script src='assets/syntaxhighlighter/scripts/shBrushPython.js' type='text/javascript'></script></#if>
  <#if brush=='xml'>
  <script src='assets/syntaxhighlighter/scripts/shBrushXml.js' type='text/javascript'></script></#if>

<link type='text/css' rel='stylesheet' href='assets/pnotify/jquery.pnotify.default.css'/>
<script src='assets/pnotify/jquery.pnotify.min.js' type='text/javascript'></script>

<script src='assets/zeroclipboard-1.3.2/ZeroClipboard.min.js' type='text/javascript'></script>

<script language='javascript' type='text/javascript'>
  $(document).ready(function () {
    jQuery.ajaxSetup({
      cache: true
    });
    ZeroClipboard.config({moviePath: 'assets/zeroclipboard-1.3.2/ZeroClipboard.swf'});
    var client = new ZeroClipboard($("#copy"));
    client.on('complete', function (client, args) {
      $('#copy').attr("class", "btn btn-success");
      $.pnotify({
        title: 'Copy Success',
        text: 'You can paste the code anywhere now.',
        history: false,
        type: 'success'
      });
    });

    var refresh = setInterval(function () {
      refreshResult();
    }, 250);
    setTimeout(function () {
      clearInterval(refresh);
    }, 25050);

    function refreshResult() {
      $('#WAIT, #RUN, #REJUDGE').each(function () {
        var $this = $(this);
        var id = $this.attr('id');
        $.getJSON('/api/problem/getResult', {'sid': ${solution.sid!}}, function (data) {
          if (data.result.name != id) {
            $this.attr('id', data.result.name);
            if(data.test == 0) {
                $this.html(data.result.longName);
            } else {
                $this.html(data.result.longName + ' on test ' + data.test);
            }
            if (data.result.name == 'AC') {
              $('.time').html(data.time);
              $('.memory').html(data.memory);
            }
            clearInterval(refresh);
          }
        });
      });
    }
  });

  SyntaxHighlighter.config.tagName = 'textarea';
  SyntaxHighlighter.all();
</script>
</@override>

<#if alpha??>
  <@extends name="../contest/_layout.html" />
<#else>
  <@extends name="../common/_layout.html" />
</#if>
